<template>
  <div class="login-containe">
    <el-card header="登录">
      <el-form @submit.native.prevent="login" >
        <el-form-item label="账号">
          <el-input v-model="model.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="model.password"></el-input>
        </el-form-item>
        <el-button type="primary" native-type="sbumit">登录</el-button>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  name: 'Login',
  data () {
    return {
      model: {
      }
    }
  },
  methods: {
    async login () {
      const res = await this.$http.post('/login', this.model)
     if(res.success && res.data.token){
       this.$message({
         type: 'success',
         message: '登录成功'
       })
       localStorage.token = res.data.token
       this.$router.push('/')
       
     }
    }
  }
}
</script>
<style scoped>
  .login-containe{
    width: 50%;
    margin: 40px auto;
  }
</style>
